<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="118px">
      <el-form-item label="排查计划名称" prop="planName">
        <el-input v-model="queryParams.planName" placeholder="请输入排查计划名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="planState">
        <el-radio-group v-model="queryParams.exeState">
          <el-radio label="0">待执行</el-radio>
          <!--<el-radio label="1">执行中</el-radio>-->
          <el-radio label="1">已执行</el-radio>
          <!--<el-radio label="3">已中止</el-radio>-->
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
<!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list">
      <!--<el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="计划名称" align="center" prop="planName" />
      <el-table-column label="排查周期" align="center" prop="checkPeriod">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.HT_CHECKPERIOD" :value="scope.row.checkPeriod" />
        </template>
      </el-table-column>
      <el-table-column label="组织级别" align="center" prop="orgLevel">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.HT_ORGLEVEL" :value="scope.row.orgLevel" />
        </template>
      </el-table-column>
      <!--<el-table-column label="剩余时间" align="center">-->
        <!--<template slot-scope="scope">-->
        <!--</template>-->
      <!--</el-table-column>-->
      <el-table-column label="本次排查开始时间" align="center" prop="startTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, "{y}-{m}-{d}")}} 00:00:00</span>
        </template>startDate
      </el-table-column>
      <el-table-column label="本次排查结束时间" align="center" prop="endTime">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.endTime, "{y}-{m}-{d}") }}  00:00:00</span>
        </template>
      </el-table-column>
      <el-table-column label="排查类型" align="center" prop="checkType">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.HT_CHECKTYPE" :value="scope.row.checkType" />
        </template>
      </el-table-column>
      <el-table-column label="排查属性" align="center" prop="checkProperty">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.HT_CHECKPROPERTY" :value="scope.row.checkProperty" />
        </template>
      </el-table-column>
      <el-table-column label="排查人" align="center" prop="checkPeo">
      </el-table-column>
      <el-table-column label="任务状态" align="center" width="120" prop="exeState">
        <template slot-scope="scope">
          <span v-if="scope.row.exeState=='0'">待执行</span>
          <span v-if="scope.row.exeState=='1'">已执行</span>
          <!--<dict-tag :type="DICT_TYPE.HT_PLANSTATE" :value="scope.row.exeState" />-->
        </template>
      </el-table-column>
      <el-table-column label="排查记录" align="center" prop="srecordNums">
        <template slot-scope="scope">
          <span>应排查{{scope.row.srecordNums}}条/已排查{{scope.row.yrecordNums}}条</span>
        </template>
      </el-table-column>
      <el-table-column label="隐患信息" align="center" width="120" prop="trecordNums">
        <template slot-scope="scope">
          <span>登记隐患{{scope.row.trecordNums}}条</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="handleDetail(scope.row)"
            >查看</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleCheckRecord(scope.row)" v-if="scope.row.exeState=='0'"
           >录入排查记录</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 查看计划 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>

      <el-table v-loading="loading1" :data="list1" height="450">
        <!--<el-table-column label="主键" align="center" prop="id" />-->
        <el-table-column label="序号" type="index" width="50" />
        <el-table-column label="所属风险点" align="center" prop="riskPoint" />
        <el-table-column label="风险等级" align="center" prop="riskLevel" width="180">
          <template slot-scope="scope">
            <dict-tag :type="DICT_TYPE.RISK_LEVEL" :value="scope.row.riskLevel" />
          </template>
        </el-table-column>
        <el-table-column label="危险源名称" align="center" prop="hazardSource" />
        <el-table-column label="管控措施" align="center" prop="controlMeasures">
        </el-table-column>
        <el-table-column label="状态" align="center" prop="riskState" v-if="state=='view'">
          <template slot-scope="scope">
            <div v-show="scope.row.riskState=='0'">正常</div>
            <div v-show="scope.row.riskState=='1'">隐患</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" v-if="state=='edit'">
          <template slot-scope="scope">
            <el-button size="mini"  type="text" @click="handleState(scope.row)"
                       >正常</el-button>
            <el-button size="mini"   type="text"  @click="addHiddentrouble(scope.row)"
                       >登记隐患</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页组件 -->
      <pagination v-show="total1 > 0" :total="total1" :page.sync="queryParams1.pageNo" :limit.sync="queryParams1.pageSize"
                  @pagination="getList1" />
      <div slot="footer" class="dialog-footer">
        <!--<el-button type="primary" @click="submitForm">确 定</el-button>-->
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
  import ElRow from "element-ui/packages/row/src/row";
  import {
    createHtPlanDetailExe,
    updateHtHiddentroublePlan,
    getHtHiddentroublePlan,
    getHtHiddenPlanExePage,
    getRiskInfoList
  } from "@/api/biz/htHiddenImplement";

  export default {
    name: "HtHiddenFormulate",
    components: {
      ElRow
    },
    data() {
      return {
        htPlanId:undefined,
        htPlanDetailId:undefined,
        htPlanExeId:undefined,
        // 遮罩层
        loading: false,
        loading1: false,
        loading2: false,
        showObject: false,
        state:'view',
        // 导出遮罩层
        exportLoading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        total1:0,
        planId:undefined,
        planExeId:undefined,
        // 隐患信息列表
        list: [],
        list1:[],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        openDetail: false,
        dateRangeCheckDate: [],
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          exeState:'0'
        },
        // 查询参数
        queryParams1: {
          pageNo: 1,
          pageSize: 10,
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          htName: [{
            required: true,
            message: "隐患名称不能为空",
            trigger: "blur"
          }],
        }
      };
    },
    created() {
      this.htPlanId=this.$route.query.planId;
      this.htPlanExeId=this.$route.query.planExeId;
      this.htPlanDetailId=this.$route.query.htPlanDetailId;
      if(this.htPlanId!=null){
        //打开录入排查记录弹窗
        let row={id:this.htPlanId}
        this.handleCheckRecord(row);
      }
        this.getList();
    },
    methods: {
      /** 查询列表 */
      getList() {
         this.loading = true;
         // 处理查询参数
         let params = {...this.queryParams};
         // 执行查询
        getHtHiddenPlanExePage(params).then(response => {
           this.list = response.data.list;
           this.total = response.data.total;
           this.loading = false;
         });
      },
      // 切换单选框
       changeRedio(event,row){
          this.currentRowId = event;
       },
      getList1(){
        this.loading1 = true;
        var that=this;
        that.list1=[];
        that.queryParams1.planId=that.planId;
        that.queryParams1.planExeId=that.planExeId;
//        that.queryParams1.exeState=undefined;
        that.queryParams1.isRegister="true";
        getHtHiddentroublePlan(that.queryParams1).then(response => {
          that.list1=response.data.list
          that.total1=response.data.total;
          that.loading1=false;
        });
      },
      // 查看详情
      handleDetail(row) {
        this.planId=row.id;
        this.planExeId=row.planExeId;
        var that=this;
        that.list1=[];
        that.queryParams1.planId=that.planId;
        that.queryParams1.planExeId=that.planExeId;
//        that.queryParams1.exeState='0';
        that.queryParams1.isRegister=undefined;
        this.loading1 = true;
        getHtHiddentroublePlan(that.queryParams1).then(response => {
          that.list1=response.data.list
          that.total1=response.data.total;
          that.loading1=false;
          that.title="查看计划详情";
          that.state='view';
          that.open = true
        });
      },
      handleCheckRecord(row){
        this.planId=row.id;
        this.planExeId=row.planExeId;
        var that=this;
        that.list1=[];
        that.queryParams1.planId=that.planId;
        that.queryParams1.planExeId=that.planExeId;
        debugger;
//        that.queryParams1.exeState=undefined;
        that.queryParams1.isRegister="true";
        this.loading1 = true;
        getHtHiddentroublePlan(that.queryParams1).then(response => {
          that.list1=response.data.list
          that.total1=response.data.total;
          that.open = true
          that.loading1=false;
          that.title="录入排查记录";
          that.state='edit';
        });
      },
      //新增
      handleAdd() {
        this.open = true
      },
      /** 取消按钮 */
      cancel() {
        this.open = false;
      },
      cancelDetail() {
        this.openDetail = false;
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1;
        this.getList();
      },
      // 更多查询
      showMore() {
        this.open = true;
      },
      changeRadio(e){

      },
      //排查项目弹窗
      openObject() {
        this.showObject = true;
      },

      /** 提交按钮 */
      submitForm() {
        this.open = false
      },

      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      handleState(row){
          const id = row.id;
          debugger;
          this.$modal.confirm('是否确认管控措施为"' + row.controlMeasures + '"的数据项状态设置为“正常”?').then(function() {
//            let form={'id':row.id,'planId':row.planId,'planExeId':row.planExeId,
//              'riskId':row.riskId,'hazardId':row.hazardId,'controlId':row.controlId,'riskState':'0'}
//            return updateHtHiddentroublePlan(form);
            let form={'planId':row.planId,'planExeId':row.planExeId,'planDetailId':row.id,'riskState':'0'};
            return createHtPlanDetailExe(form);
          }).then(() => {
            this.getList1();
            this.$modal.msgSuccess("管控措施设置状态成功");
          }).catch(() => {});
      },
      addHiddentrouble(row){
        window.close();
        this.$router.push({ path: "/ht/addHt", query: { planDetailId: row.id,planExeId:row.planExeId,planId:row.planId}});
      },
    }
  };
</script>
<style scoped>
</style>
